<?php 
class CMTahunAjaran extends MTahunAjaran{
	static public function getTahunAjaranActive($departmentId) {
		$sql = "select * from m_tahun_ajaran where department_id =:deptId and start_date <= :currentDate and end_date > :currentDate and is_active = true";			
		$currentDate = date("Y-m-d");			
		$tahunAjaran = MTahunAjaran::model()->findBySql($sql,array(":currentDate"=>$currentDate,":deptId"=>$departmentId));
		return $tahunAjaran;
	}
	
	static public function getNewPos($departmentId) {
		$sql = "select * from m_tahun_ajaran where department_id =:deptId and is_active = true order by pos desc limit 1";
		$conn = Yii::app()->db;
		$cmd = $conn->createCommand($sql);
		$rs = $cmd->query(array(":deptId"=>$departmentId));
		$result =0; 		
		while ($rw = $rs->read()) {
			//print_r($rw["pos"]);
			$result = $rw["pos"] + 1;
		}		
		return $result;
	}
		
	static public function getNextTahunAjaran($pos) {
		$mTahunAjaran = MTahunAjaran::model()->find("pos > $pos order by pos");		
		return $mTahunAjaran;
	}
	
	
}
?>